let mixinList = require('../../common/mixinList');
Page({
    behaviors: [mixinList],
    data: {
        reqUrl: '/supplier/comment',
        usePrivateMethod: true,
        product_common_id: '',
        product_id: '',
        supplier_id: '',
        evaluateScreenActive: 0, //评价筛选选中项
        evaluateScreenData: [
            { type: '全部', num: 0 },
            { type: '好评', num: 0 },
            { type: '中评', num: 0 },
            { type: '差评', num: 0 },
        ],
        scrollTop: 0
    },
    onLoad: function(options) {
        const { product_common_id, product_id, supplier_id } = options
        this.setData({ product_common_id, product_id, supplier_id })
        // this.getEvaluateNum(product_id, product_common_id, supplier_id)
        this.getList(true)
    },
    /**获取评价数量 */
    // getEvaluateNum(product_id, product_common_id, supplier_id) {
    //     const url = `/supplier/comment/tongji?product_id=${product_id}&product_common_id=${product_common_id}&supplier_id=${supplier_id}`
    //     this.request({
    //         url,
    //     }, ({ data }) => {
    //         this.setData({
    //             ['evaluateScreenData[1].num']: data.praise_count,
    //             ['evaluateScreenData[2].num']: data.medium_count,
    //             ['evaluateScreenData[3].num']: data.negative_count,
    //         })
    //     })
    // },
    getParamsData() { //页面特殊的请求参数，需要时在页面内覆盖此方法，默认返回{}
        const { product_common_id, product_id, supplier_id, evaluateScreenActive } = this.data
        return { product_common_id, product_id, supplier_id, type: evaluateScreenActive }
    },
    /**筛选条件改变 */
    onScreenChange(e) {
        const { index } = e.currentTarget.dataset
        if (index === this.data.evaluateScreenActive) return
        this.setData({ evaluateScreenActive: index, scrollTop: 0 })
        this.getList(true)
    },
    /**列表请求私有方法，设置全部评价数量 */
    privateMethod(refresh, res) {
        return new Promise(resolve => {
            this.setData({
                [`evaluateScreenData[${this.data.evaluateScreenActive}].num`]: res.count
            })
            resolve(res.data)
        })
    },
    /**预览评价图片 */
    priviewEvaluate({ mark }) {
        const { index, photo_index } = mark
        if (photo_index == undefined) return
        const sources = this.data.list[index].photos.map(item => {
            return this.data.imgHost + item
        })
        wx.previewImage({
            current: sources[photo_index],
            urls: sources
        })
    }
})